//
//  WeakEleViewController.m
//  Qihuo
//
//  Created by Vencoo on 13-12-6.
//  Copyright (c) 2013年 Vencoo. All rights reserved.
//

#import "WeakEleViewController.h"

@interface WeakEleViewController ()
{    
    NSMutableArray *sendControls;
//    NSArray *checkIds;
    NSMutableArray *realCheckIds;
    NSMutableArray *textFieldArrs;
    NSMutableArray *remarkTFs;
    NSMutableArray *childNameLBs;
    NSMutableArray *isNormals;
    NSMutableArray *selectBtnArr;
    UIImage *roundUnselect;
    UIImage *roundSelect;
}
@end

@implementation WeakEleViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    NSArray *queryDataArr = [NSArray array];
    realCheckIds = [NSMutableArray array];
    switch ([Appinfomation shareIstance].strongXunJianCount) {
        case 0:
        {
            self.title = @"弱电巡检（一）";
            queryDataArr = @[@{@"id": @"1",@"floorname":@"17F",@"rfid":@"<#string#>"},@{@"id": @"2",@"floorname":@"16F",@"rfid":@"<#string#>"},@{@"id": @"3",@"floorname":@"15F",@"rfid":@"<#string#>"},@{@"id": @"4",@"floorname":@"14F",@"rfid":@"<#string#>"},@{@"id": @"5",@"floorname":@"13F",@"rfid":@"<#string#>"},@{@"id": @"6",@"floorname":@"12F",@"rfid":@"<#string#>"},@{@"id": @"7",@"floorname":@"11F",@"rfid":@"<#string#>"},@{@"id": @"8",@"floorname":@"9F",@"rfid":@"<#string#>"},@{@"id": @"9",@"floorname":@"7FB",@"rfid":@"<#string#>"},@{@"id": @"10",@"floorname":@"7FB十轴",@"rfid":@"<#string#>"},@{@"id": @"11",@"floorname":@"6FB",@"rfid":@"<#string#>"},@{@"id": @"12",@"floorname":@"6FB十轴",@"rfid":@"<#string#>"},@{@"id": @"13",@"floorname":@"5FB十轴",@"rfid":@"<#string#>"},@{@"id": @"14",@"floorname":@"4FB",@"rfid":@"<#string#>"},@{@"id": @"15",@"floorname":@"4FB十轴",@"rfid":@"<#string#>"},@{@"id": @"16",@"floorname":@"3FB十轴",@"rfid":@"<#string#>"},@{@"id": @"17",@"floorname":@"2FB",@"rfid":@"<#string#>"},@{@"id": @"18",@"floorname":@"2FB十轴",@"rfid":@"<#string#>"},@{@"id": @"19",@"floorname":@"B1FB",@"rfid":@"<#string#>"},@{@"id": @"20",@"floorname":@"B2FB",@"rfid":@"<#string#>"},@{@"id": @"21",@"floorname":@"B3FB",@"rfid":@"<#string#>"},@{@"id": @"22",@"floorname":@"6FA",@"rfid":@"<#string#>"},@{@"id": @"23",@"floorname":@"5FA",@"rfid":@"<#string#>"},@{@"id": @"24",@"floorname":@"3FA",@"rfid":@"<#string#>"},@{@"id": @"25",@"floorname":@"2FA",@"rfid":@"<#string#>"},@{@"id": @"26",@"floorname":@"1FA",@"rfid":@"<#string#>"}];
            self.sendUrl=[NSString stringWithFormat:addWeak1];
        }
            break;
            
        default:
        {
            self.title = @"弱电巡检（二）";
            queryDataArr = @[@{@"id": @"1",@"floorname":@"37F",@"rfid":@"<#string#>"},@{@"id": @"2",@"floorname":@"36F",@"rfid":@"<#string#>"},@{@"id": @"3",@"floorname":@"35F",@"rfid":@"<#string#>"},@{@"id": @"4",@"floorname":@"34F",@"rfid":@"<#string#>"},@{@"id": @"5",@"floorname":@"33F",@"rfid":@"<#string#>"},@{@"id": @"6",@"floorname":@"32F",@"rfid":@"<#string#>"},@{@"id": @"7",@"floorname":@"31F",@"rfid":@"<#string#>"},@{@"id": @"8",@"floorname":@"30F",@"rfid":@"<#string#>"},@{@"id": @"9",@"floorname":@"29F",@"rfid":@"<#string#>"},@{@"id": @"10",@"floorname":@"28F",@"rfid":@"<#string#>"},@{@"id": @"11",@"floorname":@"27F",@"rfid":@"<#string#>"},@{@"id": @"12",@"floorname":@"26F",@"rfid":@"<#string#>"},@{@"id": @"13",@"floorname":@"25F",@"rfid":@"<#string#>"},@{@"id": @"14",@"floorname":@"24F",@"rfid":@"<#string#>"},@{@"id": @"15",@"floorname":@"23F",@"rfid":@"<#string#>"},@{@"id": @"16",@"floorname":@"22F",@"rfid":@"<#string#>"},@{@"id": @"17",@"floorname":@"21F",@"rfid":@"<#string#>"},@{@"id": @"18",@"floorname":@"20F",@"rfid":@"<#string#>"},@{@"id": @"19",@"floorname":@"19F",@"rfid":@"<#string#>"},@{@"id": @"20",@"floorname":@"18F",@"rfid":@"<#string#>"},@{@"id": @"21",@"floorname":@"10F",@"rfid":@"<#string#>"},@{@"id": @"22",@"floorname":@"8FB",@"rfid":@"<#string#>"},@{@"id": @"23",@"floorname":@"5FB",@"rfid":@"<#string#>"},@{@"id": @"24",@"floorname":@"4FA",@"rfid":@"<#string#>"},@{@"id": @"25",@"floorname":@"3FB",@"rfid":@"<#string#>"},@{@"id": @"26",@"floorname":@"1FB十轴",@"rfid":@"<#string#>"}];
            self.sendUrl=[NSString stringWithFormat:addWeak2];
        }
            break;
    }
    [super viewDidLoad];
    self.floorNames = [NSMutableArray array];
    self.floorIds = [NSMutableArray array];
    for (NSDictionary *dic in queryDataArr)
    {
        [self.floorNames addObject:[dic valueForKey:@"floorname"]];
        [self.floorIds addObject:[dic valueForKey:@"id"]];
        [self.sendFloorDatas addObject:@""];
        [self.xunJianCellInfos addObject:@{@"hidden":@"1",@"floorId":[dic valueForKey:@"id"] }];
    }
    [self initData];
    NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.myTableView selectRowAtIndexPath:index animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
- (void)initData
{
    roundSelect = [UIImage imageNamed:@"选中"];
    roundUnselect = [UIImage imageNamed:@"未选中"];
//    checkIds = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"];
    isNormals = [NSMutableArray array];
    NSDictionary *oneDic = @{@"checkID": @"1",@"checkName":@"环境",@"type":@"1",@"childName":@[@"温度"]};
    NSDictionary *twoDic = @{@"checkID": @"2",@"checkName":@"网端电源",@"type":@"2",@"childName":@[@"配电开关",@"楼层分开关",@"PDU接线端",@"PDU墙面接口"]};
    NSDictionary *threeDic = @{@"checkID": @"3",@"checkName":@"PDS机柜",@"type":@"2",@"childName":@[@"交换机供电状态",@"光纤接口灯",@"线缆标签",@"配架整齐"]};
    NSDictionary *fourDic = @{@"checkID": @"4",@"checkName":@"CCTV机柜",@"type":@"2",@"childName":@[@"机电配电开关",@"指示灯情况"]};
    NSDictionary *fiveDic = @{@"checkID": @"5",@"checkName":@"SEC箱",@"type":@"2",@"childName":@[@"指示灯常量",@"通讯指示灯",@"后备电池",@"箱内整洁",@"图纸",@"锁是否完好"]};
    NSDictionary *sixDic = @{@"checkID": @"6",@"checkName":@"FA箱",@"type":@"2",@"childName":@[@"线缆标签",@"箱内整洁",@"图纸",@"锁是否完好"]};
    NSDictionary *sevenDic = @{@"checkID": @"7",@"checkName":@"CATV箱",@"type":@"2",@"childName":@[@"线路连接状况",@"主干放大器",@"分支分配器",@"箱内整齐",@"图纸",@"锁是否完好"]};
    NSDictionary *eightDic = @{@"checkID": @"8",@"checkName":@"PA箱",@"type":@"2",@"childName":@[@"保险丝状况",@"箱内整洁",@"图纸",@"锁是否完好"]};
    self.allShowDataArr = @[oneDic,twoDic,threeDic,fourDic,fiveDic,sixDic,sevenDic,eightDic];
    [self showUIWithArray:self.allShowDataArr andFloorId:@"1"];
}
- (void)showUIWithArray:(NSArray *)array andFloorId:(NSString *)floorId
{
    [self clearAll];
    sendControls = [NSMutableArray array];
    childNameLBs = [NSMutableArray array];
    textFieldArrs = [NSMutableArray array];
    selectBtnArr = [NSMutableArray array];
    remarkTFs = [NSMutableArray array];
    [realCheckIds removeAllObjects];
    [UIView animateWithDuration:.5 animations:^{
        self.backScrollV.contentSize = CGSizeZero;
    }];
    NSLog(@"%@",self.sendFloorDatas);
    self.floorIdQuanju = floorId;
    id receiveFloorObj = [self.sendFloorDatas objectAtIndex:[self.floorIds indexOfObjectss:self.floorIdQuanju]];
    if (![receiveFloorObj isKindOfClass:[NSString class]])
    {
        self.sendCheckDatas = [receiveFloorObj objectForKey:@"checkData"];
    }
    else
    {
        self.sendCheckDatas = [NSMutableArray array];
        for (int i = 0; i < array.count; i ++)
        {
            NSString *checkID = [NSString stringWithFormat:@"%d",i+1];
            [self.sendCheckDatas addObject:@{@"checkId": checkID,@"isNormal":@"3",@"checkRemark":@""}];
        }
    }

    UIImage *textImage = [UIImage imageNamed:@"输入框底"];
    NSArray *showArr = [NSArray array];
    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
    if ([Appinfomation shareIstance].strongXunJianCount == 0)
    {
        [indexSet addIndex:0];
        [indexSet addIndex:1];
        if (([floorId integerValue] >=1 && [floorId integerValue] <= 9) || [floorId integerValue] == 19 || [floorId integerValue] == 22 || [floorId integerValue] == 23 || [floorId integerValue] == 25)
        {
            [indexSet addIndex:2];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 11)
        {
            [indexSet addIndex:2];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 12)
        {
            [indexSet addIndex:3];
            [indexSet addIndex:4];
        }
        else if ([floorId integerValue] == 10 || [floorId integerValue] == 17||[floorId integerValue] == 14)
        {
            [indexSet addIndex:2];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 13 || [floorId integerValue] == 16 ||[floorId integerValue] == 18)
        {
            [indexSet addIndex:4];
            [indexSet addIndex:6];
        }
//        else if ([floorId integerValue] == 14)
//        {
//            [indexSet addIndex:2];
//            [indexSet addIndex:5];
//            [indexSet addIndex:6];
//        }
        else if ([floorId integerValue] == 15)
        {
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:6];
        }
        else if ([floorId integerValue] == 20)
        {
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 21)
        {
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 24)
        {
            [indexSet addIndex:2];
            [indexSet addIndex:5];
            [indexSet addIndex:7];
        }
        else if ([floorId integerValue] == 26)
        {
            [indexSet addIndex:2];
            [indexSet addIndex:3];
            [indexSet addIndex:4];
            [indexSet addIndex:5];
            [indexSet addIndex:6];
            [indexSet addIndex:7];
        }
    }
    else if ([Appinfomation shareIstance].strongXunJianCount == 1)
    {
        [indexSet addIndex:0];
        [indexSet addIndex:1];
        [indexSet addIndex:2];
        [indexSet addIndex:5];
        [indexSet addIndex:6];
        [indexSet addIndex:7];
        if ([floorId integerValue] >= 1 && [floorId integerValue] <= 26 && [floorId integerValue] != 23 && [floorId integerValue] != 25)
        {
            [indexSet addIndex:4];
            if ([floorId integerValue] == 2 || [floorId integerValue] == 8 || [floorId integerValue] == 19 || [floorId integerValue] == 18 || [floorId integerValue] == 21)
            {
                [indexSet addIndex:3];
            }
        }
    }
    showArr = [array objectsAtIndexes:indexSet];
    for (int i = 0; i < showArr.count; i++)
    {
        NSDictionary *mydic = [showArr objectAtIndex:i];
        [realCheckIds addObject:[mydic valueForKey:@"checkID"]];
        NSString *type = [mydic valueForKey:@"type"];
        NSString *checkName = [mydic valueForKey:@"checkName"];
        NSArray *childNames = [mydic objectForKey:@"childName"];
        NSMutableArray *textArr = [NSMutableArray array];
        switch ([type integerValue])
        {
            case 1:
            {
                UILabel *titleLb = [UILabel new];
                titleLb.text = checkName;
                titleLb.font = [UIFont systemFontOfSize:25];
                CGSize mySz = [titleLb.text sizeWithFont:titleLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                titleLb.frame = CGRectMake(10, [[childNameLBs lastObject]frame].origin.y + [[childNameLBs lastObject]frame].size.height + interval111, mySz.width, mySz.height);
                [self.backScrollV addSubview:titleLb];
                [self.controlWillClears addObject:titleLb];

                UILabel *label = [UILabel new];
                label.text = @"温度（˚C）";
                label.font = [UIFont systemFontOfSize:25];
                mySz = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                label.frame = CGRectMake(52, titleLb.frame.origin.y + titleLb.frame.size.height + 10, mySz.width, mySz.height);
                [self.backScrollV addSubview:label];
                [childNameLBs addObject:label];
                [self.controlWillClears addObject:label];
                
                UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.origin.x + label.frame.size.width, label.frame.origin.y, 100, mySz.height)];
                textF.background = textImage;
                textF.tag = 250;
                textF.keyboardType = UIKeyboardTypeNumberPad;
                textF.delegate = self;
                textF.text = [[self.sendCheckDatas objectAtIndex:i]valueForKey:@"checkRemark"];
                [self.backScrollV addSubview:textF];
                [remarkTFs addObject:textF];
                textF.keyboardType = UIKeyboardTypeNumberPad;
                [textArr addObject:textF];
                [textFieldArrs addObject:textArr];
                [self.controlWillClears addObject:textF];
            }
                break;
            case 2:
            {
                UILabel *checkNameLb = [UILabel new];
                checkNameLb.text = checkName;
                checkNameLb.font = [UIFont systemFontOfSize:28];
                CGSize mySz = [checkNameLb.text sizeWithFont:checkNameLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                checkNameLb.frame = CGRectMake(10, [[remarkTFs lastObject]frame].origin.y + [[remarkTFs lastObject]frame].size.height + interval111, mySz.width, mySz.height);
                [self.backScrollV addSubview:checkNameLb];
                [self.controlWillClears addObject:checkNameLb];
                for (int k = 0; k < childNames.count; k++)
                {
                    UILabel *childNameLb = [UILabel new];
                    childNameLb.text = [childNames objectAtIndex:k];
                    childNameLb.font = [UIFont systemFontOfSize:20];
                    mySz = [childNameLb.text sizeWithFont:childNameLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
                    childNameLb.frame = CGRectMake(checkNameLb.frame.origin.x + interval111 * 2, checkNameLb.frame.origin.y + (mySz.height + interval111)*(k+1), mySz.width, mySz.height);
                    [self.backScrollV addSubview:childNameLb];
                    [childNameLBs addObject:childNameLb];
                    [self.controlWillClears addObject:childNameLb];
                }
                [self addSingleSelect:self.abnormals andCheckId:[realCheckIds objectAtIndex:i]];
            }
                break;
                
            default:
                break;
        }
        [isNormals addObject:@""];
    }
    if (![receiveFloorObj isKindOfClass:[NSString class]])
    {
        [self addCommentKuang:[receiveFloorObj objectForKey:@"floorRemark"]];
    }
    else
    {
        [self addCommentKuang:@""];
    }
}

- (void)addSingleSelect:(NSArray*)options andCheckId:(NSString *)checkId
{
    NSMutableArray *btnArr = [NSMutableArray array];
    id receiveFloorObj = [self.sendFloorDatas objectAtIndex:[self.floorIds indexOfObjectss:self.floorIdQuanju]];

    NSArray *receiveCheckArr = [NSArray array];
    NSString *receiveCheckId = @"";
    NSString *receiveIsnormal = @"3";
    NSString *receiveCheckRemark = @"";
    if (![receiveFloorObj isKindOfClass:[NSString class]])
    {
        receiveCheckArr = [receiveFloorObj objectForKey:@"checkData"];
        NSDictionary *receiveCheckDic = [receiveCheckArr objectAtIndex:[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"] indexOfObjectss:checkId]];
        receiveCheckId = [receiveCheckDic objectForKey:@"checkId"];
        receiveIsnormal = [receiveCheckDic objectForKey:@"isNormal"];
        receiveCheckRemark = [receiveCheckDic objectForKey:@"checkRemark"];
    }
    for (int j =0; j<options.count; j++)
    {
        UIButton *selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [selectBtn setImage:roundUnselect forState:UIControlStateNormal];
        if (j == [receiveIsnormal integerValue])
        {
            [selectBtn setImage:roundSelect forState:UIControlStateNormal];
        }
        [selectBtn addTarget:self action:@selector(selectOptions:) forControlEvents:UIControlEventTouchUpInside];
        selectBtn.frame = CGRectMake(62 + (self.backScrollV.frame.size.width - 62)/2*j, [[childNameLBs lastObject]frame].origin.y + ([[childNameLBs lastObject]frame].size.height + interval111), roundSelect.size.width, roundSelect.size.height);
        [self.backScrollV addSubview:selectBtn];
        [btnArr addObject:selectBtn];
        [self.controlWillClears addObject:selectBtn];
        
        UILabel *abnormLb = [UILabel new];
        NSString *abnormStr = [options objectAtIndex:j];
        abnormLb.font = [UIFont systemFontOfSize:26];
        abnormLb.text = abnormStr;
        CGSize mySize = [abnormLb.text sizeWithFont:abnormLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
        abnormLb.frame = CGRectMake(selectBtn.frame.origin.x + selectBtn.frame.size.width, selectBtn.frame.origin.y, mySize.width, mySize.height);
        [self.backScrollV addSubview:abnormLb];
        [self.controlWillClears addObject:abnormLb];
    }
    UILabel *remarkLb = [UILabel new];
    remarkLb.text = @"备注：";
    remarkLb.font = [UIFont systemFontOfSize:25];
    CGSize mySiz = [remarkLb.text sizeWithFont:remarkLb.font constrainedToSize:CGSizeMake(MAXFLOAT, 40)];
    remarkLb.frame = CGRectMake(50, [[childNameLBs lastObject]frame].origin.y + ([[childNameLBs lastObject]frame].size.height + interval111)*2, mySiz.width, mySiz.height);
    [self.backScrollV addSubview:remarkLb];
    [self.controlWillClears addObject:remarkLb];
    
    UITextField *remarkTf = [[UITextField alloc]initWithFrame:CGRectMake(remarkLb.frame.origin.x + remarkLb.frame.size.width, remarkLb.frame.origin.y, 300, mySiz.height)];
    remarkTf.background = [UIImage imageNamed:@"输入框底"];
    remarkTf.delegate = self;
    remarkTf.text = [receiveCheckRemark stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [self.backScrollV addSubview:remarkTf];
    [remarkTFs addObject:remarkTf];
    [selectBtnArr addObject:btnArr];
    self.backScrollV.contentSize = CGSizeMake(self.backScrollV.frame.size.width, remarkTf.frame.size.height + remarkTf.frame.origin.y + interval111);
    [self.controlWillClears addObject:remarkTf];
    //    默认选中第一行
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.myTableView) {
        return self.floorNames.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView cellForRowAtIndexPath:indexPath];
    if (tableView == self.myTableView) {
        self.mycell.textLabel.text = [self.floorNames objectAtIndex:indexPath.row];
        return self.mycell;
    }
    return nil;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self hiddenAll];
    if (tableView == self.myTableView)
    {
        [self showUIWithArray:self.allShowDataArr andFloorId:[self.floorIds objectAtIndex:indexPath.row]];
    }
}

#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField.tag == 250)
    {
        return YES;
    }
    else
    {
        for (int k = 0; k < remarkTFs.count; k ++)
        {
            id tf = [remarkTFs objectAtIndex:k];
            int index = [realCheckIds indexOfObjectss:[NSString stringWithFormat:@"%d",k]];
            NSLog(@"%d",index);
            BOOL isNormal = [[isNormals objectAtIndex:k]integerValue];
            if (isNormal == YES && tf == textField)
            {
                return YES;
            }
        }
    }    return NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
//    if (textField.tag == 250)
//    {
//        ;
//    }
//    else
//    {
        for (int k = 0; k < remarkTFs.count; k ++)
        {
            UITextField *tf = [remarkTFs objectAtIndex:k];
            if (tf == textField) {
                NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[realCheckIds objectAtIndex:k],@"checkId",@"1",@"isNormal",[textField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],@"checkRemark",nil];
                [self.sendCheckDatas replaceObjectAtIndex:[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"]indexOfObjectss:[realCheckIds objectAtIndex:k] ] withObject:dic];
                NSLog(@"sendCheckData = %@",self.sendCheckDatas);
            }
//        }
    }
}

#pragma mark - button action
- (void)selectOptions:(id)sender
{
    UIButton *btn = (UIButton*)sender;
    for (int a = 0;a<selectBtnArr.count;a++)
    {
        NSArray *btnArr = [selectBtnArr objectAtIndex:a];
        if ([btnArr containsObject:btn])
        {
            for (int j = 0;j<btnArr.count;j++)
            {
                UIButton *seleBtn = [btnArr objectAtIndex:j];
                [seleBtn setImage:roundUnselect forState:UIControlStateNormal];
                if (btn == [btnArr objectAtIndex:j])
                {
                    [seleBtn setImage:roundSelect forState:UIControlStateNormal];
                    [isNormals replaceObjectAtIndex:a+1 withObject:[NSString stringWithFormat:@"%d",j]];
                    UITextField *tf =(UITextField*)[remarkTFs objectAtIndex:a+1];
                    if (j == 0)
                    {
                        [[[UIApplication sharedApplication]keyWindow]endEditing:YES];
                        tf.text = @"";
                    }
                    else if (j == 1)
                    {
                        [tf becomeFirstResponder];
                    }
                    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[realCheckIds objectAtIndex:a+1],@"checkId",[NSString stringWithFormat:@"%d",j],@"isNormal",@"",@"checkRemark",nil];
                    [self.sendCheckDatas replaceObjectAtIndex:[@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"] indexOfObject:[realCheckIds objectAtIndex:a+1]]withObject:dic];
                    NSLog(@"checkData1 = %@",self.sendCheckDatas);
                }
            }
        }
    }
}

#pragma mark - end
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
